package com.githan.bootsecurity.config;

import com.githan.bootsecurity.response.Result;
import com.githan.bootsecurity.response.ResultCode;
import org.springframework.security.web.session.InvalidSessionStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author https://github.com/Han56
 * @date 2021/4/11 19:29
 */
@Component
public class MyInvalidSessionStrategy extends JSONAuthentication implements InvalidSessionStrategy {


//    自定义会话超时处理器

    @Override
    public void onInvalidSessionDetected(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
        Result result=Result.error(ResultCode.USER_ACCOUNT_EXPIRED);
        this.WriteJSON(httpServletRequest,httpServletResponse,result);
    }
}
